package com.uh.microservice.core.controller;

import com.uh.microservice.core.dto.AkkaMsg;
import com.uh.microservice.core.service.AsyncService;
import com.uh.microservice.core.service.StepService;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

/**
 * 通用通道Controller
 * Created by liming on 2017/9/15.
 */
@RestController
@RequestMapping("/step")
public class StepController extends BaseSupport{
    @Autowired
    private StepService service;

    @Autowired
    private AsyncService asyncService;

    /**
     * 查询
     * @return String
     */
    @RequestMapping("/qry")
    @ResponseBody
    public String qry(){
        return output(service.qry(getInputParam()));
    }

    /**
     * 分页查询
     * @return String
     */
    @RequestMapping("/pageq/{code}")
    @ResponseBody
    public String qryp(@PathVariable String  code){
        return output(service.qryp(code,getInputParam()));
    }

    /**
     * 新增、修改、删除数据
     * @return String
     */
    @RequestMapping("/dui")
    @ResponseBody
    public String dui(){
        return output(service.dui(getInputParam()));
    }

    /**
     * 异步方法调用，适用于处理逻辑比较复杂需要马上返回的应用场景
     * @return String
     */
    @RequestMapping("/async")
    @ResponseBody
    public String async(){
        Map data=getInputParam();

        Integer id=(int)Math.round(Math.random()*100);
        Long waitTime=10L;
        AkkaMsg akkaMsg=new AkkaMsg("stepService.doSync",data,id,waitTime);
        asyncService.tell(akkaMsg);
        return this.output(akkaMsg);
    }

}
